/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {Form, Input, Radio, Select, InputNumber, TreeSelect, Switch, Tooltip,Icon} from 'antd';
import {connect} from 'dva';
import find from 'lodash/find'
const FormItem = Form.Item;
const {TextArea} = Input;
import request from '@/utils/request';
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data:{}
    };
  }
  componentDidMount() {
    const that=this;
    request(`/configs`,{
      method:'GET',
      params:{
        region_id:localStorage.getItem('area_id')?localStorage.getItem('area_id'):'6901726763131338752',
      }
    }).then((response)=>{
      if(response.status===200){
        that.setState({
          data:response.data.data
        },function (){
          this.props.form.setFieldsValue ({
            consumption_abnormality_value:that.state.data.consumption_abnormality_value,
            alarm_contact_numbers:that.state.data.alarm_contact_numbers,
          })
        });

      }
    });
  }
  render() {
    const formItemLayoutWithLabel2 = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 14},
      }
    };
    const {getFieldDecorator} = this.props.form;
    const that=this
    return (
      <div>
        <Form >
          <FormItem
            {...formItemLayoutWithLabel2}
            label={(
              <span>
                报警值
                  </span>
            )}
          >
            {getFieldDecorator('consumption_abnormality_value', {
              initialValue: '',
              rules: [{required: true, message:'报警值不能为空'}],
            })(
              <InputNumber min={0} style={{width:'100%'}} addonAfter="m³"/>
            )}
          </FormItem>
          <FormItem
            label={<span>报警手机号<Tooltip
              title="多个号码之间逗号分隔">
             <Icon type="question-circle" />
            </Tooltip></span>}
            {...formItemLayoutWithLabel2}
          >
            {getFieldDecorator('alarm_contact_numbers', {})(
              <TextArea rows={3}/>
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);
